﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.Company
{
    public partial class CompanyGoodsList : BasePage
    {
        HZ.Supervise.Model.ProcureCatalog procata = new HZ.Supervise.Model.ProcureCatalog();
        HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
        IBLL_User iu = BLLFactory.BLL_User();
        KeyOperationLogJG kj; 
        public CompanyGoodsList()
        {
            this.ModuleNo = Module.耗材配送汇总管理.ToString();
            this.PageOperateType = OperateType.产品信息列表.ToString();
        }
         
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //if (CurrentAccount.GetUser().Org.Area.AreaID != Constants.CURRENT_DEPLOY_AREAID)
                //{
                //    ddlCity.SelectedValue = CurrentAccount.GetUser().Org.Area.AreaID;
                //    ddlCity.Enabled = false;
                //}
                ddlArea.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                CompanyGoodsList_DataBind();
            }
        }

        /// <summary>
        /// 绑定数据源方法
        /// 董辉
        /// 2011-3-29 16:44
        /// </summary>
        private void CompanyGoodsList_DataBind()
        {
            int t = 0; 
            string areaid = "";
            //if (!string.IsNullOrEmpty(ddlCity.SelectedValue))
            //{
            //    areaid = ddlCity.SelectedValue;
            //}
            areaid = ddlArea.SelectedAreaID;
            procata.CompanyName_SC = HZ.Supervise.DAL.DAL_Helper.Replace(txtProduceCompany_SC.Text.Trim());
            procata.Outlookc = HZ.Supervise.DAL.DAL_Helper.Replace(txtOutLook.Text.Trim());
            procata.Unit = HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.Trim());
            procata.GoodsID = HZ.Supervise.DAL.DAL_Helper.Replace(txtGoodsID.Text.Trim());
            procata.RegName = HZ.Supervise.DAL.DAL_Helper.Replace(txtRegName.Text.Trim());
            procata.Brand = HZ.Supervise.DAL.DAL_Helper.Replace(txtBrand.Text.Trim());
            procata.ProductName = HZ.Supervise.DAL.DAL_Helper.Replace(txtProductName.Text.Trim());
            procata.GoodsName = HZ.Supervise.DAL.DAL_Helper.Replace(tGoodsName.Text.Trim());
            System.Data.DataTable dt = iEC.GetCompanyGoodsListByAreaID(areaid,procata, this.AspNetPager_CompanyGoodsList.CurrentPageIndex, AspNetPager_CompanyGoodsList.PageSize, out t);
            AspNetPager_CompanyGoodsList.RecordCount = t; 
            gvwPSLInfo.PageSize = AspNetPager_CompanyGoodsList.PageSize; 
            this.gvwPSLInfo.DataSource = dt; 
            this.gvwPSLInfo.DataBind();
            AddLog(string.Format("查询产品信息列表高值数据!(产品信息列表)"));
        }

        /// <summary>
        /// 查询数据事件
        /// 董辉
        /// 2011-3-29 16:42
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.AspNetPager_CompanyGoodsList.CurrentPageIndex = 1;
        }

        /// <summary>
        /// 导出数据事件
        /// 董辉
        /// 2011-3-29 16:43
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            int t = 0;
            string areaid = ddlArea.SelectedAreaID;
            HZ.Supervise.Model.ProcureCatalog procata = new HZ.Supervise.Model.ProcureCatalog();
            procata.CompanyName_SC = HZ.Supervise.DAL.DAL_Helper.Replace(txtProduceCompany_SC.Text.Trim());
            procata.Outlookc = HZ.Supervise.DAL.DAL_Helper.Replace(txtOutLook.Text.Trim());
            procata.Unit = HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.Trim());
            procata.GoodsID = HZ.Supervise.DAL.DAL_Helper.Replace(txtGoodsID.Text.Trim());
            procata.RegName = HZ.Supervise.DAL.DAL_Helper.Replace(txtRegName.Text.Trim());
            procata.Brand = HZ.Supervise.DAL.DAL_Helper.Replace(txtBrand.Text.Trim());
            procata.ProductName = HZ.Supervise.DAL.DAL_Helper.Replace(txtProductName.Text.Trim());
            procata.GoodsName = HZ.Supervise.DAL.DAL_Helper.Replace(tGoodsName.Text.Trim());
            System.Data.DataTable dt = iEC.GetCompanyGoodsListByAreaID(areaid, procata, 0, 0, out t);//iEC.GetCompanyGoodsList(procata, 0, 0, out t);
            AddLog(string.Format("导出产品信息列表高值数据成功!(产品信息列表)"));
            ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
        }

        /// <summary>
        /// 分页事件
        /// 董辉
        /// 2011-3-29 16:53
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyGoodsList_PageChanged(object sender, EventArgs e)
        {
            CompanyGoodsList_DataBind();
        }
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="msg"></param>
        private void AddLog(string msg)
        {
            kj = new KeyOperationLogJG();
            kj.OperationLogSerialID = Guid.NewGuid().ToString();
            kj.Operator = CurrentAccount.GetUser().UserID;
            kj.OrgID = CurrentAccount.GetUser().Org.OrgID;
            kj.OperateTime = DateTime.Now;
            kj.OperateMessage = msg;
            iu.AddKeyOperationLog(kj);
        }
    }
}
